/**
 ******************************************************************************
 * @file    mx_stdio.c
 * @author  William Xu
 * @version V1.0.0
 * @date    9-Apr-2018
 * @brief   Initialize uart for printf output
 ******************************************************************************
 *
 * Copyright (c) 2009-2018 MXCHIP Co.,Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************
 */
#include <stdio.h>
#include "mx_hal.h"


void mx_hal_stdio_init(void)
{
	mx_status err;
/*
	ringbuffer_init(&stdio_rx, cli_buffer, MX_CLI_RX_BUF_SIZE);
	err = mx_hal_uart_init(&cli_uart_dev);
	require_noerr(err, exit);
*/

#ifdef MX_CLI_ENABLE
	pthread_t ntid;
/*
	pthread_mutex_init(&stdio_mtx, NULL);
	err = pthread_create(&ntid, NULL, cli_recv_task, NULL);
	require_noerr(err, exit);
*/
	err = cli_init();
	require_noerr(err, exit);
#endif

exit:
	return;
}

#ifdef MX_CLI_ENABLE
int mx_hal_cli_putstr(const char* str, uint32_t strlen)
{
	int ret = 0;
	//ret = mx_hal_uart_send(&cli_uart_dev, str, strlen, 0);
	ret = stdio_io_write(str, strlen);
	return ret;
}

int mx_hal_cli_getc(void)
{
	uint8_t ch;

	if( stdio_io_read(&ch, 1) ==1){
		return ch;
	}else{
		return -1;
	}
/*
	if (at_async_read(&ch, 1) == 1) {
		return ch;
		} else {
		return -1;
	}
	*/
}

#endif